<template>
  <div>
    <div class="gva-form-box">
      <el-form :model="formData" label-position="right" label-width="80px">
        <el-form-item label="点击程序的id:">
          <el-input v-model.number="formData.programId" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="用户id:">
          <el-input v-model.number="formData.userId" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="时间yyyyMMdd格式支付穿:">
          <el-input v-model="formData.createData" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="创建时间:">
          <el-date-picker v-model="formData.createTime" type="date" placeholder="选择日期" clearable></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button size="mini" type="primary" @click="save">保存</el-button>
          <el-button size="mini" type="primary" @click="back">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  createProgramJoinInfo,
  updateProgramJoinInfo,
  findProgramJoinInfo
} from '@/api/programJoinInfo' //  此处请自行替换地址
import infoList from '@/mixins/infoList'
export default {
  name: 'ProgramJoinInfo',
  mixins: [infoList],
  data() {
    return {
      type: '',
      formData: {
        programId: 0,
        userId: 0,
        createData: '',
        createTime: new Date(),
      }
    }
  },
  async created() {
    // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (this.$route.query.id) {
      const res = await findProgramJoinInfo({ ID: this.$route.query.id })
      if (res.code === 0) {
        this.formData = res.data.reprogramJoinInfo
        this.type = 'update'
      }
    } else {
      this.type = 'create'
    }
  },
  methods: {
    async save() {
      let res
      switch (this.type) {
        case 'create':
          res = await createProgramJoinInfo(this.formData)
          break
        case 'update':
          res = await updateProgramJoinInfo(this.formData)
          break
        default:
          res = await createProgramJoinInfo(this.formData)
          break
      }
      if (res.code === 0) {
        this.$message({
          type: 'success',
          message: '创建/更改成功'
        })
      }
    },
    back() {
      this.$router.go(-1)
    }
  }
}
</script>

<style>
</style>
